<!DOCTYPE html>
<html lang="zh-cn">
<head>
  
    <link type="text/css" rel="stylesheet" href="/bundles/blog-common.css?v=KOZafwuaDasEedEenI5aTy8aXH0epbm6VUJ0v3vsT_Q1"/>
<link id="MainCss" type="text/css" rel="stylesheet" href="/skins/ThinkInside/bundle-ThinkInside.css?v=RRjf6pEarGnbXZ86qxNycPfQivwSKWRa4heYLB15rVE1"/>
<link type="text/css" rel="stylesheet" href="/blog/customcss/428549.css?v=%2fam3bBTkW5NBWhBE%2fD0lcyJv5UM%3d"/>

</head>
<body>
<a name="top"></a>

<div id="page_begin_html"></div><script>load_page_begin_html();</script>


<div id="main">
	<div id="mainContent">
	<div class="forFlow">
		
        <div id="post_detail">
<!--done-->
<div id="topics">
	<div class = "post">
		<h1 class = "postTitle">
			<a id="cb_post_title_url" class="postTitle2" href="https://www.cnblogs.com/frankdeng/p/9018177.html">Zookeeper（一）CentOS7.5搭建Zookeeper3.4.12集群与命令行操作</a>
		</h1>
		<div class="clear"></div>
		<div class="postBody">
			<div id="cnblogs_post_body" class="blogpost-body"><h2 class="topic">一. 分布式安装部署</h2>
<h3 style="text-align: left;" align="center">1.0 下载地址</h3>
<p class="topic">官网首页：&nbsp;<a href="https://zookeeper.apache.org/" target="_blank">https://zookeeper.apache.org/</a></p>
<p class="topic">下载地址：&nbsp;<a href="http://mirror.bit.edu.cn/apache/zookeeper/" target="_blank">http://mirror.bit.edu.cn/apache/zookeeper/</a></p>
<p class="topic"><img src="https://images2018.cnblogs.com/blog/1385722/201807/1385722-20180725235615506-205949843.png" alt="" /></p>
<div class="notesContainer">
<h3 class="topic">1.1 集群规划</h3>
<p class="topic">在node21、node22和ode23三个节点上部署Zookeeper，三个节点都已安装jdk。</p>
<table style="height: 105px; background-color: #21ddbc; width: 312px;" border="0">
<tbody>
<tr>
<td style="text-align: center;">IP</td>
<td style="text-align: center;">节点名称</td>
<td style="text-align: center;">Zookeeper</td>
<td style="text-align: center;">JDK</td>
</tr>
<tr>
<td style="text-align: center;">192.168.100.21</td>
<td style="text-align: center;">node21</td>
<td style="text-align: center;">Zookeeper</td>
<td style="text-align: center;">JDK</td>
</tr>
<tr>
<td style="text-align: center;">192.168.100.22</td>
<td style="text-align: center;">node22</td>
<td style="text-align: center;">Zookeeper</td>
<td style="text-align: center;">JDK</td>
</tr>
<tr>
<td style="text-align: center;">192.168.100.23</td>
<td style="text-align: center;">node23</td>
<td style="text-align: center;">Zookeeper</td>
<td style="text-align: center;">JDk</td>
</tr>
</tbody>
</table>
<h3 class="topic">1.2 解压安装</h3>
<p>（1）解压zookeeper安装包到/opt/module/目录下</p>
<div class="cnblogs_code">
<pre>[admin@node21 software]$ tar -zxvf zookeeper-3.4.12.tar.gz -C /opt/module/</pre>
</div>
<p>（2）在/opt/module/zookeeper-3.4.12/这个目录下创建Data</p>
<div class="cnblogs_code">
<pre>[admin@node21 zookeeper-3.4.12]# sudo mkdir  Data</pre>
</div>
<p>（3）重命名/opt/module/zookeeper-3.4.12/conf这个目录下的zoo_sample.cfg为zoo.cfg</p>
<div class="cnblogs_code">
<pre>[admin@node21 conf]# mv zoo_sample.cfg zoo.cfg</pre>
</div>
<h3>1.3 配置zoo.cfg文件</h3>
<p>具体配置，修改dateDir,添加日志存放目录</p>
<div class="cnblogs_code">
<pre>dataDir=/opt/module/zookeeper-3.4.12/Data<br />dataLogDir=/opt/module/zookeeper-3.4.12/logs</pre>
</div>
<p>末尾增加如下配置</p>
<div class="cnblogs_code">
<pre>server.1=node21:2888:3888
server.2=node22:2888:3888
server.3=node23:2888:3888</pre>
</div>
<h3>1.4 集群配置</h3>
<p>（1）在/opt/module/zookeeper-3.4.12/Data目录下创建一个myid的文件</p>
<div class="cnblogs_code">
<pre>[admin@node21 Data]# sudo touch myid</pre>
</div>
<p>（2）编辑myid文件，&nbsp;在文件中添加与server对应的编号：如&nbsp;1&nbsp;&nbsp;&nbsp;</p>
<div class="cnblogs_code">
<pre>[admin@node21 Data]# vi myid</pre>
</div>
<p>（3）拷贝配置好的zookeeper到其他机器上</p>
<div class="cnblogs_code">
<pre>[admin@node21 module]# scp -r zookeeper-3.4.12/ admin@node22:/opt/module/
[admin@node21 module]# scp -r zookeeper-3.4.12/ admin@node23:/opt/module/</pre>
</div>
<p>并分别修改node22，node23中myid文件中内容为2、3</p>
<div class="cnblogs_code">
<pre>[admin@node22 Data]# echo <span style="color: #800080;">2</span> &gt; <span style="color: #000000;">myid
[admin@node23 Data]</span># echo <span style="color: #800080;">3</span> &gt; myid</pre>
</div>
<h3>1.5 启动集群</h3>
<p>（1）分别启动zookeeper</p>
<div class="cnblogs_code">
<pre>[admin@node21 zookeeper-3.4.12]# bin/zkServer.sh start
[admin@node22 zookeeper-3.4.12]# bin/zkServer.sh start
[admin@node23 zookeeper-3.4.12]# bin/zkServer.sh start</pre>
</div>
<p>（2）查看状态</p>
<div class="cnblogs_code">
<pre>[admin@node21 zookeeper-3.4.12]# bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/module/zookeeper-3.4.12/bin/../conf/zoo.cfg
Mode: follower
[admin@node22 zookeeper-3.4.12]# bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/module/zookeeper-3.4.12/bin/../conf/zoo.cfg
Mode: follower
[admin@node23 zookeeper-3.4.12]# bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/module/zookeeper-3.4.12/bin/../conf/zoo.cfg
Mode: leader</pre>
</div>
<p class="topic">（3）停止zookeeper</p>
<div class="cnblogs_code">
<pre>[admin@node21 zookeeper-<span style="color: #800080;">3.4</span>.<span style="color: #800080;">12</span>]$ bin/zkServer.sh stop</pre>
</div>
<h3>1.6 配置环境变量</h3>
<div class="cnblogs_code">
<pre>[admin@node21 zookeeper-<span style="color: #800080;">3.4</span>.<span style="color: #800080;">12</span>]$ sudo vi /etc/profile <br />export ZOOKEEPER_HOME=/opt/module/zookeeper-<span style="color: #800080;">3.4</span>.<span style="color: #800080;">12</span> <br />export PATH=$PATH:$ZOOKEEPER_HOME/bin</pre>
</div>
<h3 class="topic">1.7zoo.cfg配置参数解读</h3>
<p>Server.A=B:C:D。</p>
<p>A是一个数字，表示这个是第几号服务器；</p>
<p>B是这个服务器的ip地址；</p>
<p>C是这个服务器与集群中的Leader服务器交换信息的端口；</p>
<p>D是万一集群中的Leader服务器挂了，需要一个端口来重新进行选举，选出一个新的Leader，而这个端口就是用来执行选举时服务器相互通信的端口。</p>
<p>集群模式下配置一个文件myid，这个文件在dataDir目录下，这个文件里面有一个数据就是A的值，Zookeeper启动时读取此文件，拿到里面的数据与zoo.cfg里面的配置信息比较从而判断到底是哪个server。</p>
<p class="topic">1）tickTime=2000：通信心跳数</p>
<div class="notesContainer">
<p><span class="s1">tickTime：通信心跳数，Zookeeper服务器心跳时间，单位毫秒</span></p>
<p><span class="s1">Zookeeper使用的基本时间，服务器之间或客户端与服务器之间维持心跳的时间间隔，也就是每个tickTime时间就会发送一个心跳，时间单位为毫秒。</span></p>
<p><span class="s1">它用于心跳机制，并且设置最小的session超时时间为两倍心跳时间。(session的最小超时时间是2*tickTime)</span></p>
</div>
<p class="topic">2）initLimit=10：LF初始通信时限</p>
<div class="notesContainer">
<p><span class="s1">集群中的follower跟随者服务器(F)与leader领导者服务器(L)之间初始连接时能容忍的最多心跳数（tickTime的数量），用它来限定集群中的Zookeeper服务器连接到Leader的时限。</span></p>
<p><span class="s1">投票选举新leader的初始化时间</span></p>
<p><span class="s1">Follower在启动过程中，会从Leader同步所有最新数据，然后确定自己能够对外服务的起始状态。</span></p>
<p><span class="s1">Leader允许F在initLimit时间内完成这个工作。</span></p>
</div>
<p class="topic">3）syncLimit=5：LF同步通信时限</p>
<p><span class="s1">集群中Leader与Follower之间的最大响应时间单位，假如响应超过syncLimit * tickTime，</span></p>
<p><span class="s1">Leader认为Follwer死掉，从服务器列表中删除Follwer。</span></p>
<p><span class="s1">在运行过程中，Leader负责与ZK集群中所有机器进行通信，例如通过一些心跳检测机制，来检测机器的存活状态。</span></p>
<p><span class="s1">如果L发出心跳包在syncLimit之后，还没有从F那收到响应，那么就认为这个F已经不在线了。</span></p>
<div class="notesContainer">
<p><span class="s1">4）dataDir：数据文件目录+数据持久化路径</span></p>
<p><span class="s1">保存内存数据库快照信息的位置，如果没有其他说明，更新的事务日志也保存到数据库。</span></p>
</div>
<p class="topic">&nbsp;5）clientPort=2181：客户端连接端口</p>
<div class="notesContainer">
<p><span class="s1">监听客户端连接的端口</span></p>
</div>
<h2 class="topic">二. 客户端命令行操作</h2>
<h3 class="topic">1）启动客户端</h3>
<div class="notesContainer">
<div class="cnblogs_code">
<pre>[admin@node21 zookeeper-<span style="color: #800080;">3.4</span>.<span style="color: #800080;">12</span>]$ zkCli.sh </pre>
</div>
</div>
<h3 class="topic">2）显示所有操作命令</h3>
<div class="notesContainer">
<div class="cnblogs_code">
<pre>[zk: localhost:<span style="color: #800080;">2181</span>(CONNECTED) <span style="color: #800080;">0</span><span style="color: #000000;">] help
ZooKeeper </span>-<span style="color: #000000;">server host:port cmd args
    stat path [watch]
    </span><span style="color: #0000ff;">set</span><span style="color: #000000;"> path data [version]
    ls path [watch]
    delquota [</span>-n|-<span style="color: #000000;">b] path
    ls2 path [watch]
    setAcl path acl
    setquota </span>-n|-<span style="color: #000000;">b val path
    history 
    redo cmdno
    printwatches on</span>|<span style="color: #000000;">off
    delete path [version]
    sync path
    listquota path
    rmr path
    </span><span style="color: #0000ff;">get</span><span style="color: #000000;"> path [watch]
    create [</span>-s] [-<span style="color: #000000;">e] path data acl
    addauth scheme auth
    quit 
    getAcl path
    close 
    connect host:port</span></pre>
</div>
</div>
<h3 class="topic">3）查看当前znode中所包含的内容</h3>
<div class="notesContainer">
<div class="cnblogs_code">
<pre>[zk: localhost:<span style="color: #800080;">2181</span>(CONNECTED) <span style="color: #800080;">1</span>] ls /<span style="color: #000000;">
[zookeeper]</span></pre>
</div>
</div>
<h3 class="topic">4）查看当前节点数据并能看到更新次数等数据</h3>
<div class="cnblogs_code">
<pre>[zk: localhost:<span style="color: #800080;">2181</span>(CONNECTED) <span style="color: #800080;">2</span>] ls2 /<span style="color: #000000;">
[zookeeper]
cZxid </span>= <span style="color: #800080;">0x0</span><span style="color: #000000;">
ctime </span>= Wed Dec <span style="color: #800080;">31</span> <span style="color: #800080;">19</span>:<span style="color: #800080;">00</span>:<span style="color: #800080;">00</span> EST <span style="color: #800080;">1969</span><span style="color: #000000;">
mZxid </span>= <span style="color: #800080;">0x0</span><span style="color: #000000;">
mtime </span>= Wed Dec <span style="color: #800080;">31</span> <span style="color: #800080;">19</span>:<span style="color: #800080;">00</span>:<span style="color: #800080;">00</span> EST <span style="color: #800080;">1969</span><span style="color: #000000;">
pZxid </span>= <span style="color: #800080;">0x0</span><span style="color: #000000;">
cversion </span>= -<span style="color: #800080;">1</span><span style="color: #000000;">
dataVersion </span>= <span style="color: #800080;">0</span><span style="color: #000000;">
aclVersion </span>= <span style="color: #800080;">0</span><span style="color: #000000;">
ephemeralOwner </span>= <span style="color: #800080;">0x0</span><span style="color: #000000;">
dataLength </span>= <span style="color: #800080;">0</span><span style="color: #000000;">
numChildren </span>= <span style="color: #800080;">1</span></pre>
</div>
<h3 class="topic">5）创建普通节点</h3>
<div class="notesContainer">
<div class="cnblogs_code">
<pre>[zk: localhost:<span style="color: #800080;">2181</span>(CONNECTED) <span style="color: #800080;">3</span>] create /opt <span style="color: #800000;">"</span><span style="color: #800000;">aa</span><span style="color: #800000;">"</span><span style="color: #000000;">
Created </span>/<span style="color: #000000;">opt
[zk: localhost:</span><span style="color: #800080;">2181</span>(CONNECTED) <span style="color: #800080;">4</span>] create /opt/module <span style="color: #800000;">"</span><span style="color: #800000;">bb</span><span style="color: #800000;">"</span><span style="color: #000000;">
Created </span>/opt/module</pre>
</div>
</div>
<h3 class="topic">6）获得节点的值</h3>
<div class="notesContainer">
<div class="cnblogs_code">
<pre>[zk: localhost:<span style="color: #800080;">2181</span>(CONNECTED) <span style="color: #800080;">5</span>] <span style="color: #0000ff;">get</span> /<span style="color: #000000;">opt
aa
cZxid </span>= <span style="color: #800080;">0x4100000004</span><span style="color: #000000;">
ctime </span>= Wed Jul <span style="color: #800080;">25</span> <span style="color: #800080;">07</span>:<span style="color: #800080;">48</span>:<span style="color: #800080;">55</span> EDT <span style="color: #800080;">2018</span><span style="color: #000000;">
mZxid </span>= <span style="color: #800080;">0x4100000004</span><span style="color: #000000;">
mtime </span>= Wed Jul <span style="color: #800080;">25</span> <span style="color: #800080;">07</span>:<span style="color: #800080;">48</span>:<span style="color: #800080;">55</span> EDT <span style="color: #800080;">2018</span><span style="color: #000000;">
pZxid </span>= <span style="color: #800080;">0x4100000005</span><span style="color: #000000;">
cversion </span>= <span style="color: #800080;">1</span><span style="color: #000000;">
dataVersion </span>= <span style="color: #800080;">0</span><span style="color: #000000;">
aclVersion </span>= <span style="color: #800080;">0</span><span style="color: #000000;">
ephemeralOwner </span>= <span style="color: #800080;">0x0</span><span style="color: #000000;">
dataLength </span>= <span style="color: #800080;">2</span><span style="color: #000000;">
numChildren </span>= <span style="color: #800080;">1</span><span style="color: #000000;">
[zk: localhost:</span><span style="color: #800080;">2181</span>(CONNECTED) <span style="color: #800080;">6</span>] <span style="color: #0000ff;">get</span> /opt/<span style="color: #000000;">module
bb
cZxid </span>= <span style="color: #800080;">0x4100000005</span><span style="color: #000000;">
ctime </span>= Wed Jul <span style="color: #800080;">25</span> <span style="color: #800080;">07</span>:<span style="color: #800080;">51</span>:<span style="color: #800080;">21</span> EDT <span style="color: #800080;">2018</span><span style="color: #000000;">
mZxid </span>= <span style="color: #800080;">0x4100000005</span><span style="color: #000000;">
mtime </span>= Wed Jul <span style="color: #800080;">25</span> <span style="color: #800080;">07</span>:<span style="color: #800080;">51</span>:<span style="color: #800080;">21</span> EDT <span style="color: #800080;">2018</span><span style="color: #000000;">
pZxid </span>= <span style="color: #800080;">0x4100000005</span><span style="color: #000000;">
cversion </span>= <span style="color: #800080;">0</span><span style="color: #000000;">
dataVersion </span>= <span style="color: #800080;">0</span><span style="color: #000000;">
aclVersion </span>= <span style="color: #800080;">0</span><span style="color: #000000;">
ephemeralOwner </span>= <span style="color: #800080;">0x0</span><span style="color: #000000;">
dataLength </span>= <span style="color: #800080;">2</span><span style="color: #000000;">
numChildren </span>= <span style="color: #800080;">0</span></pre>
</div>
</div>
<h3 class="topic">7）创建短暂节点</h3>
<div class="cnblogs_code">
<pre>[zk: localhost:<span style="color: #800080;">2181</span>(CONNECTED) <span style="color: #800080;">7</span>] create -e /app <span style="color: #800080;">8888</span><span style="color: #000000;">           
Created </span>/<span style="color: #000000;">app</span><span style="color: #000000;"><br /></span></pre>
</div>
<pre><span>（1）在当前客户端是能查看到的</span></pre>
<div class="cnblogs_code">
<pre>[zk: localhost:<span style="color: #800080;">2181</span>(CONNECTED) <span style="color: #800080;">8</span>] ls /<span style="color: #000000;">
[app, opt, zookeeper]</span></pre>
</div>
<pre><span>（2<span>）退出当前客户端然后再重启启动客户端</span></span></pre>
<div class="cnblogs_code">
<pre>[zk: localhost:<span style="color: #800080;">2181</span>(CONNECTED) <span style="color: #800080;">9</span><span style="color: #000000;">] quit
[root@node21 zookeeper</span>-<span style="color: #800080;">3.4</span>.<span style="color: #800080;">12</span>]$ bin/zkCli.sh</pre>
</div>
<pre><span>（3<span>）再次查看根目录下短暂节点已经删除</span></span></pre>
<div class="cnblogs_code">
<pre>[zk: localhost:<span style="color: #800080;">2181</span>(CONNECTED) <span style="color: #800080;">0</span>] ls /<span style="color: #000000;">
[opt, zookeeper]</span></pre>
</div>
<h3 class="topic">8）创建带序号的节点</h3>
<pre>（1<span>）先创建一个普通的根节点app</span></pre>
<div class="notesContainer">
<div class="cnblogs_code">
<pre><span style="color: #000000;">[zk: localhost:</span><span style="color: #800080;">2181</span>(CONNECTED) <span style="color: #800080;">1</span>] create /app <span style="color: #800000;">"</span><span style="color: #800000;">app</span><span style="color: #800000;">"</span><span style="color: #000000;">
create </span>/app <span style="color: #800000;">"</span><span style="color: #800000;">app</span><span style="color: #800000;">"</span><span style="color: #000000;"><br /></span></pre>
</div>
</div>
<pre><span>（2<span>）创建带序号的节点</span></span></pre>
<div class="cnblogs_code">
<pre>[zk: localhost:<span style="color: #800080;">2181</span>(CONNECTED) <span style="color: #800080;">2</span>] create -s /app/aa <span style="color: #800080;">888</span><span style="color: #000000;">
Created </span>/app/<span style="color: #000000;">aa0000000000
[zk: localhost:</span><span style="color: #800080;">2181</span>(CONNECTED) <span style="color: #800080;">3</span>] create -s /app/bb <span style="color: #800080;">888</span><span style="color: #000000;">
Created </span>/app/<span style="color: #000000;">bb0000000001
[zk: localhost:</span><span style="color: #800080;">2181</span>(CONNECTED) <span style="color: #800080;">4</span>] create -s /app/cc <span style="color: #800080;">888</span><span style="color: #000000;">
Created </span>/app/cc0000000002</pre>
</div>
<pre><span>如果原节点下有1个节点，则再排序时从1开始，以此类推。</span></pre>
<div class="cnblogs_code">
<pre>[zk: localhost:<span style="color: #800080;">2181</span>(CONNECTED) <span style="color: #800080;">5</span>] create -s /opt/aa <span style="color: #800080;">888</span><span style="color: #000000;">
Created </span>/opt/aa0000000001</pre>
</div>
<h3 class="topic">9）修改节点数据值</h3>
<div class="notesContainer">
<div class="cnblogs_code">
<pre>[zk: localhost:<span style="color: #800080;">2181</span>(CONNECTED) <span style="color: #800080;">6</span>] <span style="color: #0000ff;">set</span> /opt <span style="color: #800080;">999</span><span style="color: #000000;">
cZxid </span>= <span style="color: #800080;">0x4100000004</span><span style="color: #000000;">
ctime </span>= Wed Jul <span style="color: #800080;">25</span> <span style="color: #800080;">07</span>:<span style="color: #800080;">48</span>:<span style="color: #800080;">55</span> EDT <span style="color: #800080;">2018</span><span style="color: #000000;">
mZxid </span>= <span style="color: #800080;">0x410000000e</span><span style="color: #000000;">
mtime </span>= Wed Jul <span style="color: #800080;">25</span> <span style="color: #800080;">08</span>:<span style="color: #800080;">14</span>:<span style="color: #800080;">18</span> EDT <span style="color: #800080;">2018</span><span style="color: #000000;">
pZxid </span>= <span style="color: #800080;">0x410000000d</span><span style="color: #000000;">
cversion </span>= <span style="color: #800080;">2</span><span style="color: #000000;">
dataVersion </span>= <span style="color: #800080;">1</span><span style="color: #000000;">
aclVersion </span>= <span style="color: #800080;">0</span><span style="color: #000000;">
ephemeralOwner </span>= <span style="color: #800080;">0x0</span><span style="color: #000000;">
dataLength </span>= <span style="color: #800080;">3</span><span style="color: #000000;">
numChildren </span>= <span style="color: #800080;">2</span></pre>
</div>
</div>
<h3 class="topic">10）节点的值变化监听</h3>
<div class="notesContainer">
<p><span class="s1">（1）在node22主机上注册监听/opt节点数据变化</span></p>
<div class="cnblogs_code">
<pre>[admin@node22 ~<span style="color: #000000;">]$ zkCli.sh 
[zk: localhost:</span><span style="color: #800080;">2181</span>(CONNECTED) <span style="color: #800080;">0</span>] <span style="color: #0000ff;">get</span> /opt watch</pre>
</div>
<p><span class="s1">（2）在node21主机上修改/opt节点的数据</span></p>
<div class="cnblogs_code">
<pre>[zk: localhost:<span style="color: #800080;">2181</span>(CONNECTED) <span style="color: #800080;">7</span>] <span style="color: #0000ff;">set</span> /opt <span style="color: #800080;">777</span></pre>
</div>
<p><span class="s1">（3）观察node22主机收到数据变化的监听</span></p>
<div class="cnblogs_code">
<pre>[zk: localhost:<span style="color: #800080;">2181</span>(CONNECTED) <span style="color: #800080;">1</span><span style="color: #000000;">] 
WATCHER::

WatchedEvent state:SyncConnected type:NodeDataChanged path:</span>/opt</pre>
</div>
</div>
<h3 class="topic">11）节点的子节点变化监听（路径变化）</h3>
<div class="notesContainer">
<p><span class="s1">（1）在node22主机上注册监听/opt节点的子节点变化</span></p>
<div class="cnblogs_code">
<pre>[zk: localhost:<span style="color: #800080;">2181</span>(CONNECTED) <span style="color: #800080;">2</span>] ls /<span style="color: #000000;">opt watch
[aa0000000001, module]</span></pre>
</div>
<p><span class="s1">（2）在node21主机/opt节点上创建子节点</span></p>
<div class="cnblogs_code">
<pre>[zk: localhost:<span style="color: #800080;">2181</span>(CONNECTED) <span style="color: #800080;">8</span>] create /opt/bb <span style="color: #800080;">666</span><span style="color: #000000;">
Created </span>/opt/bb</pre>
</div>
<p><span class="s1">（3）观察node22主机收到子节点变化的监听</span></p>
<div class="cnblogs_code">
<pre>[zk: localhost:<span style="color: #800080;">2181</span>(CONNECTED) <span style="color: #800080;">3</span><span style="color: #000000;">] 
WATCHER::

WatchedEvent state:SyncConnected type:NodeChildrenChanged path:</span>/opt</pre>
</div>
</div>
<h3 class="topic">12）删除节点</h3>
<div class="notesContainer">
<div class="cnblogs_code">
<pre>[zk: localhost:<span style="color: #800080;">2181</span>(CONNECTED) <span style="color: #800080;">9</span>] delete /opt/bb</pre>
</div>
</div>
<h3 class="topic">13）递归删除节点</h3>
<div class="notesContainer">
<div class="cnblogs_code">
<pre>[zk: localhost:<span style="color: #800080;">2181</span>(CONNECTED) <span style="color: #800080;">10</span>] rmr /opt</pre>
</div>
</div>
<h3 class="topic">14）查看节点状态</h3>
<div class="notesContainer">
<div class="cnblogs_code">
<pre>[zk: localhost:<span style="color: #800080;">2181</span>(CONNECTED) <span style="color: #800080;">14</span>] stat /<span style="color: #000000;">app
cZxid </span>= <span style="color: #800080;">0x4100000009</span><span style="color: #000000;">
ctime </span>= Wed Jul <span style="color: #800080;">25</span> <span style="color: #800080;">08</span>:<span style="color: #800080;">09</span>:<span style="color: #800080;">56</span> EDT <span style="color: #800080;">2018</span><span style="color: #000000;">
mZxid </span>= <span style="color: #800080;">0x4100000009</span><span style="color: #000000;">
mtime </span>= Wed Jul <span style="color: #800080;">25</span> <span style="color: #800080;">08</span>:<span style="color: #800080;">09</span>:<span style="color: #800080;">56</span> EDT <span style="color: #800080;">2018</span><span style="color: #000000;">
pZxid </span>= <span style="color: #800080;">0x410000000c</span><span style="color: #000000;">
cversion </span>= <span style="color: #800080;">3</span><span style="color: #000000;">
dataVersion </span>= <span style="color: #800080;">0</span><span style="color: #000000;">
aclVersion </span>= <span style="color: #800080;">0</span><span style="color: #000000;">
ephemeralOwner </span>= <span style="color: #800080;">0x0</span><span style="color: #000000;">
dataLength </span>= <span style="color: #800080;">3</span><span style="color: #000000;">
numChildren </span>= <span style="color: #800080;">3</span></pre>
</div>
<h3 class="topic">15）退出客户端</h3>
<div class="cnblogs_code">

</body>
</html>
